package com.zzy.forum3.controller;


import com.zzy.forum3.common.AppResult;
import com.zzy.forum3.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/*
表示发挥的结果是数据而不是url
 */
@Api(tags="测试类的相关接口")
@RestController
@RequestMapping("/test")
public class Testcontroller {
    @ApiOperation("测试接口1")
    @GetMapping("/hello")
    public String hello(){
        return "hello,spring-boot";
    }

    @ApiOperation("测试接口4，按照传进来的姓名显示信息")
    @PostMapping("/helloByName")
    public AppResult helloByName(@ApiParam("姓名") @RequestParam("name") String name){
        return AppResult.success("hello:"+name);
    }

    @ApiOperation("显示跑出来的异常信息")
    @GetMapping("/exception")
    public AppResult testException () throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @ApiOperation("显示自定义的异常信息")
    @GetMapping("/appException")
    public AppResult testApplicationException () {
        throw new ApplicationException("这是一个ApplicationException...");
    }
}
